<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\DbConnection\Model\Model;
use Hyperf\Utils\Collection;

/**
 */
class UserTypeRule extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'user_type_rules';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [];

    /**
     * 根据性别获取等级
     * @param $gender
     * @return array
     */
    public static function getUserGradeByGender($gender): array
    {
        return self::where('gender',$gender)->orderBy('type_id','desc')->get()->toArray();
    }

    /**
     * 获取推荐的等级
     * @param $gender
     * @param $typeId
     * @return \Hyperf\Database\Model\Builder|\Hyperf\Database\Model\Model|object|null
     */
    public static function getRecommendType($gender,$typeId)
    {
        return self::where([
            ['gender','=',$gender],
            ['type_id','=',$typeId]
        ])->first('recommend_type');
    }
}